From ba58c796b02a4929681b42024a7e16e6ba1c6ec8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Timm=20B=C3=A4der?= Date: Thu, 18 May 2017 10:11:54 +0200 Subject: [PATCH] sizerequest: Stop checking orientation in query_size_for_orientation Since we have ->measure now, we can implement this code more elegantly. --- gtk/gtksizerequest.c | 116 ++++++++++++++----------------------------- 1 file changed, 37 insertions(+), 79 deletions(-) diff --git a/gtk/gtksizerequest.c b/gtk/gtksizerequest.c index a818cb8e4d..8d50b78161 100644 --- a/gtk/gtksizerequest.c +++ b/gtk/gtksizerequest.c @@ -117,8 +117,8 @@ static void gtk_widget_query_size_for_orientation (GtkWidget *widget, GtkOrientation orientation, gint for_size, - gint *minimum_size, - gint *natural_size, + gint *minimum, + gint *natural, gint *minimum_baseline, gint *natural_baseline) { @@ -148,84 +148,42 @@ gtk_widget_query_size_for_orientation (GtkWidget *widget, if (!found_in_cache) { - gint adjusted_min, adjusted_natural, adjusted_for_size = for_size; + int adjusted_min, adjusted_natural, adjusted_for_size = for_size; - if (orientation == GTK_ORIENTATION_HORIZONTAL) + if (for_size < 0) { - if (for_size < 0) - { - push_recursion_check (widget, orientation); - widget_class->measure (widget, GTK_ORIENTATION_HORIZONTAL, -1, - &min_size, &nat_size, NULL, NULL); - pop_recursion_check (widget, orientation); - } - else - { - gint minimum_height; - gint natural_height; - int dummy; - - /* Pull the base natural height from the cache as it's needed to adjust - * the proposed 'for_size' */ - widget_class->measure (widget, GTK_ORIENTATION_VERTICAL, -1, - &minimum_height, &natural_height, &dummy, &dummy); - - /* convert for_size to unadjusted height (for_size is a proposed allocation) */ - gtk_widget_adjust_size_allocation (widget, - GTK_ORIENTATION_VERTICAL, - &minimum_height, - &natural_height, - &dummy, - &adjusted_for_size); - - push_recursion_check (widget, orientation); - widget_class->measure (widget, - GTK_ORIENTATION_HORIZONTAL, - MAX (adjusted_for_size, minimum_height), - &min_size, &nat_size, - NULL, NULL); - pop_recursion_check (widget, orientation); - } + push_recursion_check (widget, orientation); + widget_class->measure (widget, orientation, -1, + &min_size, &nat_size, + &min_baseline, &nat_baseline); + pop_recursion_check (widget, orientation); } else { - if (for_size < 0) - { - push_recursion_check (widget, orientation); - widget_class->measure (widget, - GTK_ORIENTATION_VERTICAL, - -1, - &min_size, &nat_size, - &min_baseline, &nat_baseline); - pop_recursion_check (widget, orientation); - } - else - { - gint minimum_width; - gint natural_width; - int dummy; - - /* Pull the base natural width from the cache as it's needed to adjust - * the proposed 'for_size' */ - widget_class->measure (widget, GTK_ORIENTATION_HORIZONTAL, -1, - &minimum_width, &natural_width, &dummy, &dummy); - - /* convert for_size to unadjusted width (for_size is a proposed allocation) */ - gtk_widget_adjust_size_allocation (widget, - GTK_ORIENTATION_HORIZONTAL, - &minimum_width, - &natural_width, - &dummy, - &adjusted_for_size); - - push_recursion_check (widget, orientation); - widget_class->measure (widget, - GTK_ORIENTATION_VERTICAL, - MAX (adjusted_for_size, minimum_width), - &min_size, &nat_size, - &min_baseline, &nat_baseline); - pop_recursion_check (widget, orientation); - } + int dummy = 0; + int minimum_size; + int natural_size; + + /* Pull the base natural size from the cache as it's needed to adjust + * the proposed 'for_size' */ + widget_class->measure (widget, OPPOSITE_ORIENTATION (orientation), -1, + &minimum_size, &natural_size, &dummy, &dummy); + + gtk_widget_adjust_size_allocation (widget, + OPPOSITE_ORIENTATION (orientation), + &minimum_size, + &natural_size, + &dummy, + &adjusted_for_size); + + push_recursion_check (widget, orientation); + widget_class->measure (widget, + orientation, + MAX (adjusted_for_size, minimum_size), + &min_size, &nat_size, + &min_baseline, &nat_baseline); + pop_recursion_check (widget, orientation); + } if (G_UNLIKELY (min_size > nat_size)) @@ -310,11 +268,11 @@ gtk_widget_query_size_for_orientation (GtkWidget *widget, nat_baseline); } - if (minimum_size) - *minimum_size = min_size; + if (minimum) + *minimum = min_size; - if (natural_size) - *natural_size = nat_size; + if (natural) + *natural = nat_size; if (minimum_baseline) *minimum_baseline = min_baseline; -- 2.30.2